package com.ac.input.web.action.input;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.caac.core.web.action.BaseAction;
import com.caac.core.web.form.BaseForm;
import com.ac.input.dao.ReportsDao;
import com.ac.input.web.form.DataSearchForm;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright AgileCentury 2004</p>
 * <p>Company: AgileCentury</p>
 * @author <a href="mailto:lianzs@tom.com">Lianzs</a>
 * @version 1.0
 */

public class DeleteDataAction extends BaseAction {
	   protected ActionForward doExecute(ActionMapping mapping, BaseForm form,
               HttpServletRequest request,
               HttpServletResponse response) throws Exception {
       DataSearchForm myForm = (DataSearchForm) form;
         ReportsDao rpsDao = (ReportsDao) this.getBean("reportsDao");

        if (myForm.isFirst()) {
            myForm.setRhid(rpsDao.getHndInpDefById(myForm.getMendId()));
            myForm.setFirst(false);
        }

        String whereStr = " where 1=1 ";
        if (myForm.getWhereStr()!=null && !"".equals(myForm.getWhereStr())) {
            whereStr += " and (" + myForm.getWhereStr() + ")";
        }else{
    		return forward(mapping);
        }
        
        this.getJdbcTemplate().execute("Delete from "+myForm.getRhid().getTabName()+" A"+ whereStr );
        
        if("1".equals(myForm.getIsDef())){
        	String acPath = "/pages/protected/"+myForm.getAcPath()+".jsp";
    		return new ActionForward(acPath);
        }
		return forward(mapping);
    }
}
